import numpy as np
import pandas as pd
from flask import Flask, render_template
from scipy import stats

app = Flask(__name__,
            static_folder='static',
            )

#ctx = app.app_context()
#ctx.push()

df = pd.read_csv("history_Index_k_data.csv")
close = df.iloc[1459:, 5]
prec = df.iloc[1459:, 6]
growth_rate = (close / prec - 1) * 100


@app.route('/pdf')
def test_pdf():
    with app.app_context():
        gkde = stats.gaussian_kde(dataset=growth_rate)
        x = np.linspace(start=-3, stop=3, num=200)
        y = gkde.evaluate(x)
        return render_template('pdf.html', x=x.tolist(), y=y.tolist())


@app.route('/cdf')
def test_cdf():
    with app.app_context():
        res = stats.ecdf(growth_rate)
        x1= res.cdf.quantiles
        y1 = res.cdf.probabilities
        return render_template('cdf.html', x=list(x1), y=list(y1))

if __name__ == '__main__':
    #print('test')
    app.run(debug=True,host='0.0.0.0',port=5050)